
const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

const db=cloud.database();

exports.main = async (event, context) => {
  const {account}=event.data;
  try{
    const userinfo=await db.collection("teacher").where({
      account:account,
    }).get();
    if(userinfo.data.length==1){
      let count = await db.collection('student').count()
      count = count.total
      let res=[];
      for(let i=0;i<count;i+=100){
        let userlist=await db.collection("student").where({
          grade:userinfo.data[0].grade
        }).field({
          account:true,
          name:true,
          health_insurance_check:true
        }).skip(i).get();
        res=res.concat(userlist.data)
      }
      return {success:true,message:res}
    }else{
      return{success:false,message:"获取失败"}
    }
  }catch(error){
      console.error(error);
      return{success:false,message:"error"}
  }
};